from fastapi.responses import JSONResponse
from pydantic import conint

from common.base.base_routers import get_custom_router
from services.attenuators.api import AttenuatorsApi
from services.attenuators.schemas.configs import AttenuatorsConfig
from settings import settings


att_api = AttenuatorsApi()
attenuators_router = get_custom_router(att_api, prefix='/attenuators', tags=['attenuators'])


@attenuators_router.post('/set-attenuators/', response_class=JSONResponse)
async def set_attenuators(config: AttenuatorsConfig):
    return await att_api.set_attenuators(config)


@attenuators_router.get('/get-all-attenuators/', response_class=JSONResponse)
async def get_attenuators():
    return await att_api.get_attenuators()


@attenuators_router.get('/get-attenuator/', response_class=JSONResponse)
async def get_attenuator(index: conint(ge=0, lt=settings.ATTENUATORS_NUMBER)):
    return await att_api.get_attenuator(index)
